package com.ebt.m.wiki.adapter;

/**
 * Created by Damon.Han on 2016/6/12 0012.
 */

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ebt.m.R;
import com.ebt.m.wiki.bean.PropertyBean;

import java.util.List;


public class ListPopup4MainProductsAdapter extends BaseAdapter {
    private List<PropertyBean> mArrayList;
    private Context mContext;
    private int checkedId;

    class ViewHolder {
        ImageView img;
        TextView txt;
    }

    public ListPopup4MainProductsAdapter(Context context, List<PropertyBean> list, int checkedId) {
        this.mArrayList = list;
        this.mContext = context;
        this.checkedId = checkedId;
    }

    @Override
    public int getCount() {
        if (mArrayList == null) {
            return 0;
        } else {
            return this.mArrayList.size();
        }
    }

    @Override
    public Object getItem(int position) {
        if (mArrayList == null) {
            return null;
        } else {
            return this.mArrayList.get(position);
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.wiki_item_main_produtct_menu, parent, false);
            holder.txt = (TextView) convertView.findViewById(R.id.txt);
            holder.img = (ImageView) convertView.findViewById(R.id.img_checked);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (this.mArrayList != null) {
            final PropertyBean itemName = this.mArrayList.get(position);
            holder.txt.setText(itemName.txt);
            if (itemName.key == checkedId) {
                holder.img.setVisibility(View.VISIBLE);
                convertView.setBackgroundColor(Color.parseColor("#F7F7F7"));
            } else {
                holder.img.setVisibility(View.INVISIBLE);
                convertView.setBackgroundResource(R.drawable.listview_item_background2);
            }
        }
        return convertView;
    }
}

